package com.easyaop.test.core.demo;

import com.easyaop.api.advisor.AspectjExpressionPointcut;
import com.easyaop.api.pointcut.ClassObject;
import com.easyaop.api.pointcut.MethodObject;
import net.bytebuddy.agent.ByteBuddyAgent;

import java.lang.instrument.Instrumentation;

public class Eltest {
    public void test_aop表达式() throws Exception {

        Instrumentation instrumentation = ByteBuddyAgent.install();
        AspectjExpressionPointcut pointcut = new AspectjExpressionPointcut("@annotation(com.easyaop.test.core.annotation.Log) ");

        String className = "com.easyaop.test.core.entity.MyBean2";
        boolean aClass = pointcut.isClass(new ClassObject.ForUnloaded(className));
        System.out.println(aClass);

        //        com.easyaop.test.core.entity.MyBean2 myBean2 = new com.easyaop.test.core.entity.MyBean2();
        boolean say = pointcut.isMethod(new MethodObject.ForString(className, "say", "(Ljava/lang/Object;)Ljava/lang/String;"));
        System.out.println(say);

        Class[] allLoadedClasses = instrumentation.getAllLoadedClasses();
        for (Class allLoadedClass : allLoadedClasses) {
            if (allLoadedClass.getName().equals(className)) {
                System.out.println(allLoadedClass.getName());
            }
        }
    }
}
